package com.scs.application.modules.fsd.controller;

import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.core.utils.StringUtils;
import com.scs.application.modules.fsd.entity.FsdChestUser;
import com.scs.application.modules.fsd.service.ChestUserService;
import com.scs.application.modules.sys.model.RestResult;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Description: 柜号用户权限
 */
@RestController
@RequestMapping("/back_front/chests_users")
public class ChestUserController extends CrudController<ChestUserService, FsdChestUser> {

    @GetMapping(value = "/getUsersByChestService")
    public RestResult getUsersByChest(@RequestParam("id") String id){
        return RestResult.ok("获取该智能柜所能使用的用户成功",service.getUsersByChest(id));
    }

    @PostMapping(value = "/changeUsersByChestService")
    public RestResult changeUsersByChest(@RequestBody Map<String, String> map) {
        if (service.changeUsersByChest(StringUtils.stringArryExtract(map.get("idAry"), "userId"), map.get("id")))
            return RestResult.ok("保存成功！");
        return RestResult.error("保存失败！");
    }

    @GetMapping(value = "/getChestsAndStationsByUserService")
    public RestResult getChestsAndStationsByUserId(@RequestParam("id") String id){
        return RestResult.ok("获取该用户所拥有的权限成功",service.getChestsAndStationsByUserId(id));
    }

    @PostMapping(value = "/changeChestsByUserService")
    public RestResult changeChestsByUser(@RequestBody Map<String, String> map) {
        System.out.println(map);
        if (service.changeChestsByUser(StringUtils.stringArryExtract(map.get("idAry"), "chestId"), map.get("id")))
            return RestResult.ok("保存成功！");
        return RestResult.error("保存失败！");
    }
}
